{% extends "management/base.html" %}
{% block title %}查看图书{% endblock %}

{% block content %}

<div class="container my-4">
    <div class="row">
        <div class="col-md-10 offset-md-1">
            <div class="row">
                <div class="col-md-6">
                    {% if book.image_set.all %}
                        <div id="carouselExampleIndicators" class="carousel slide" data-bs-ride="true">
                            <!-- Indicators -->
                            <div class="carousel-indicators">
                                {% for img in book.image_set.all %}
                                    <button type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide-to="{{ forloop.counter0 }}"
                                        aria-label="Slide {{ forloop.counter }}" {% if forloop.first %}class="active" aria-current="true"{% endif %}></button>
                                {% endfor %}
                            </div>

                            <!-- Slides -->
                            <div class="carousel-inner">
                                {% for img in book.image_set.all %}
                                    <div class="carousel-item {% if forloop.first %}active{% endif %}">
                                        <img src="{{ img.img.url }}" class="d-block w-100" alt="Book Image {{ forloop.counter }}">
                                    </div>
                                {% endfor %}
                            </div>

                            <!-- Controls -->
                            <button class="carousel-control-prev" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="prev">
                                <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                                <span class="visually-hidden">Previous</span>
                            </button>
                            <button class="carousel-control-next" type="button" data-bs-target="#carouselExampleIndicators" data-bs-slide="next">
                                <span class="carousel-control-next-icon" aria-hidden="true"></span>
                                <span class="visually-hidden">Next</span>
                            </button>
                        </div>
                    {% else %}
                        <p class="text-center">暂无图片</p>
                    {% endif %}
                </div>
                <div class="col-md-6">
                    <h2 class="text-center">{{ book.name }}</h2>
                    <br>
                    <h3>作者：{{ book.author }}</h3>
                    <h3>类别：{{ book.category }}</h3>
                    <h3>出版日期：{{ book.publish_date|date:"Y-m-d" }}</h3>
                    <h3>价格：{{ book.price|floatformat:2 }}</h3>
                </div>
            </div>
        </div>
    </div>
</div>

{% endblock %}